PANF=/home/cmbpanfs-01/yanghoch
source ~/.bashrc
echo $0
if [ $# -ne 3 ]; then
	echo "The function sort and merge two bed file"
	echo "The 1st arg is the 1st BED file."
	echo "The 2nd arg is the 2nd BED file."
	echo "The 3rd arg is the output file."
	echo "Three arguments are needed."
	echo "$# is provided."
	exit
fi
MKey=2
mKey=3
tmpfile="tmp.tmp"
sort $1 -k 2,2'n' -k 3,3'n' -u > $tmpfile
mv $tmpfile $1
cp $1 1_$(basename $1)
sort $2 -k 2,2'n' -k 3,3'n' -u > $tmpfile
mv $tmpfile $2
cp $2 2_$(basename $2)

cat $1 > $tmpfile
cat $2 >> $tmpfile
echo "sort files $3"
#sort $tmpfile -k $MKEY','$MKEY'n' -k $mKey','$mKEY'n' -u
sort $tmpfile -k 2,2'n' -k 3,3'n' -u > $3
#sort $tmpfile
\rm $tmpfile


